<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\ServiceArea;
use App\Models\Highway;

class ServiceAreaController extends Controller
{
    private $markers = [
    					'1-1' =>'红色半圆',
    					'1'   =>'红色实心圆',
    					'2-1' =>'紫色半圆',
    					'2'   =>'紫色实心圆',
    					'3-1' =>'黄色半圆',
    					'3'   =>'黄色实心圆',
    					'4'   =>'绿色半圆',
    					'4-1' =>'绿色实心圆',
    					'5'   =>'蓝色实心圆',
    					'5-1' =>'蓝色半圆',
    					'6'   =>'灰色空心圆',
    				];

    public function index()
    {

        $list = ServiceArea::paginate(20);
        return view('admin.servicearea.index',compact('list'));
    
    }

    public function add()
    {
    	// 之前添加的服务区
        $pre      = ServiceArea::orderBy('created_at','desc')->first();
        $highways = Highway::get();
        $markers  = $this->markers;
        $serviceareas = ServiceArea::where(['highway_id'=>$pre->highway_id])->get();
    	return view('admin.servicearea.add',compact('markers','highways','pre','serviceareas'));
    }

    public function save(Request $request)
    {
    	$rs['status'] = 'warning';
    	$rs['msg'] = '操作失败';
    	$data = $request->except(['_token']);
    	$flag = ServiceArea::create($data);
    	if($flag) {
    		$rs['status'] = 'success';
    		$rs['msg'] = '操作成功';
    		return back()->with('rs',$rs);
    	}

    	return back()->with('rs',$rs);

    }
}
